import { Application } from 'egg';

 export default (app: Application) => {
     const { controller, router,io } = app;

    io.of('/').route('chat',io.controller.chat.index);
    io.of('/').route('check',io.controller.chat.check);

    /**
     * @api {post} /api/admin/login 后台登录
     * @apiName login
     * @apiGroup admin
     *
     * @apiParam {String} admin_username 账号.
     * @apiParam {String} admin_password 密码.
     *
     * @apiSuccess {int} code 返回状态码（1：登录成功，2：登录失败，3：服务器出错，4：参数不全）
     * @apiSuccess {String} msg 返回状态码对应的信息
     * @apiSuccess {Object} data 返回的数据
     * @apiSuccess {String} data.token 登录成功后返回的token
     * @apiSuccess {String} data.admin_username 管理员账号
     *
     */
    router.post('/api/admin/login', controller.admin.login);

    /**
     * @api {post} /api/project/createProject 创建项目
     * @apiName createProject
     * @apiGroup project
     *
     * @apiParam {String} project_name 项目名.
     * @apiParam {String} project_picture 主图.
     * @apiParam {String} project_content 内容.
     *
     */
    router.post('/api/project/createProject', controller.project.createProject);

    /**
     * @api {post} /api/project/deleteProject 删除项目
     * @apiName deleteProject
     * @apiGroup project
     *
     * @apiParam {String} project_id 项目Id.
     *
     */
    router.post('/api/project/deleteProject', controller.project.deleteProject);

    /**
     * @api {post} /api/project/updateProject 修改项目
     * @apiName updateProject
     * @apiGroup project
     *
     * @apiParam {String} project_id 项目Id.
     * @apiParam {String} project_name 项目名.
     * @apiParam {String} project_picture 主图.
     * @apiParam {String} project_content 内容.
     *
     */
    router.post('/api/project/updateProject', controller.project.updateProject);

    /**
     * @api {post} /api/project/searchProject 查找项目
     * @apiName searchProject
     * @apiGroup project
     *
     * @apiParam {String} [project_name] 项目名.
     * 
     * @apiSuccess {Object} data 返回的数据
     * @apiSuccess {String} data.project_id 项目id
     * @apiSuccess {String} data.project_name 项目名
     * @apiSuccess {String} data.project_picture 项目主图
     * @apiSuccess {String} data.project_content 项目内容
     *
     */
    router.post('/api/project/searchProject', controller.project.searchProject);

    /**
     * @api {post} /api/project/searchProjectById 根据Id查找项目详情
     * @apiName searchProjectById
     * @apiGroup project
     *
     * @apiParam {String} project_id 项目id.
     * 
     * @apiSuccess {Object} data 返回的数据
     * @apiSuccess {String} data.project_name 项目名
     * @apiSuccess {String} data.project_picture 项目主图
     * @apiSuccess {String} data.project_content 项目内容
     *
     */
    router.post('/api/project/searchProjectById', controller.project.searchProjectById);

    /**
     * @api {post} /api/news/createNews 添加新闻
     * @apiName createNews
     * @apiGroup news
     *
     * @apiParam {String} news_title 新闻标题.
     * @apiParam {String} news_summary 新闻简介.
     * @apiParam {String} news_detail 新闻内容.
     *
     */
    router.post('/api/news/createNews', controller.news.createNews);

    /**
     * @api {post} /api/news/deleteNews 删除新闻
     * @apiName deleteNews
     * @apiGroup news
     *
     * @apiParam {String} news_id 新闻Id.
     *
     */
    router.post('/api/news/deleteNews', controller.news.deleteNews);

    /**
     * @api {post} /api/news/updateNews 修改新闻
     * @apiName updateNews
     * @apiGroup news
     *
     * @apiParam {String} news_id 新闻Id.
     * @apiParam {String} news_title 新闻标题.
     * @apiParam {String} news_summary 新闻简介.
     * @apiParam {String} news_detail 新闻内容.
     *
     */
    router.post('/api/news/updateNews', controller.news.updateNews);

    /**
     * @api {post} /api/news/searchNews 查找新闻
     * @apiName searchNews
     * @apiGroup news
     *
     * @apiParam {String} [news_title] 新闻标题.
     * 
     * @apiSuccess {Object} data 返回的数据
     * @apiSuccess {String} data.news_id 新闻id
     * @apiSuccess {String} data.news_title 新闻标题
     * @apiSuccess {String} data.news_summary 新闻简介
     * @apiSuccess {String} data.news_detail 新闻内容
     * @apiSuccess {String} data.created_at 创建时间
     *
     */
    router.post('/api/news/searchNews', controller.news.searchNews);

    /**
     * @api {post} /api/news/searchNewsById 根据Id查找新闻详情
     * @apiName searchNewsById
     * @apiGroup news
     *
     * @apiParam {String} news_id 新闻id.
     * 
     * @apiSuccess {Object} data 返回的数据
     * @apiSuccess {String} data.news_title 新闻标题
     * @apiSuccess {String} data.news_summary 新闻简介
     * @apiSuccess {String} data.news_detail 新闻内容
     * @apiSuccess {String} data.created_at 创建时间
     *
     */
    router.post('/api/news/searchNewsById', controller.news.searchNewsById);

    /**
     * @api {post} /api/upload/upload 上传图片
     * @apiName upload
     * @apiGroup upload
     *
     * 
     * @apiSuccess {Object} data 返回的数据
     * @apiSuccess {String} data.imgName 图片名称.
     *
     */
    router.post('/api/upload/upload', controller.upload.upload);

};
